package org.csu.jpetstorespringversion.model;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

@Data
@Repository
@TableName(value = "lineitem")
public class LineItem {
    private static final long serialVersionUID = 6804536240033522156L;
@TableId(value = "orderid")
    private int orderId;
    @TableId(value = "linenum")
    private int lineNumber;
    @TableId(value = "quantity")
    private int quantity;
    @TableId(value = "itemid")
    private String itemId;
    @TableId(value = "unitprice")
    private BigDecimal unitPrice;
    private Item item;
    private BigDecimal total;
  public LineItem(){}
    public LineItem(int lineNumber, CartItem cartItem) {
        this.lineNumber = lineNumber;
        this.quantity = cartItem.getQuantity();
        this.itemId = cartItem.getItem().getItemId();
        this.unitPrice = cartItem.getItem().getListPrice();
        this.item = cartItem.getItem();
    }
    private void calculateTotal() {
        if (item != null && item.getListPrice() != null) {
            total = item.getListPrice().multiply(new BigDecimal(quantity));
        } else {
            total = null;
        }
    }
}
